<?php

namespace Home\Controller;

use Think\Controller;

/**
 * 站点管理控制器
 * @author cheng
 */
class StationController extends BaseController {

    public function __construct() {
        parent::__construct();
    }

    /**
     * @desc 获取站点列表接口
     * @author cheng
     */
    public function stationList() {
        $param = I('post.');
        $page = intval($param['currentPage']) <= 1 ? 1 : intval($param['currentPage']);
        $pageSize = intval($param['pageSize']) <= 0 ? 10 : intval($param['pageSize']);

        $user = new \Home\Model\UserModel();
        $map['u.f_user_type_id'] = 0;
        $map['u.f_addition_status'] = 1;
        !empty($param['sname']) && $map['u.f_station_name'] = trim($param['sname']);
        !empty($param['mobile']) && $map['u.f_user_mobile'] = trim($param['mobile']);
        !empty($param['user_name']) && $map['u.f_user_name'] = trim($param['user_name']);
        !empty($param['province']) && $map['u.f_province_id'] = trim($param['province']);
        !empty($param['city']) && $map['u.f_city_id'] = trim($param['city']);
        !empty($param['area']) && $map['u.f_area_id'] = trim($param['area']);
        !empty($param['proxy_name']) && $map['u.f_proxy_id'] = trim($param['proxy_name']);
        $param['user_type'] != '' && $map['u.f_user_status'] = trim($param['user_type']);
        if ($param['proxy_notice'] == '0') {
            $map['_string'] = ' ISNULL(u.f_proxy_id) ';
        } elseif ($param['proxy_notice'] == '1') {
            $map['u.f_proxy_id'] = array('neq', 'null');
        }
        !empty($param['user_address']) && $map['u.f_address'] = array('like', '%' . trim($param['user_address']) . '%');
        //代理名称为空且 地址不为空
        if (empty($param['proxy_name']) && !empty($param['proxy_province'])) {
            $u_id = D('Home/User')->where(array('f_user_type_id' => 2, 'f_province_id' => $param['proxy_province']))->getField('f_user_id', true);
            $up_map['f_proxy_id'] = array('in', $u_id);
            $up_id = $user->where($up_map)->getField('f_user_id', true);
            $map['u.f_user_id'] = array('in', $up_id);
        }

        //获取站点信息列表
        $data = $user->getStationList($map, $page, $pageSize);
        $return = array(
            'totalRows' => $data['count'],
            'totalPages' => ceil($data['count'] / $pageSize),
            'currentPage' => $page,
            'stationList' => $data['list']
        );
        $this->output(true, $return);
    }
    



}
